/*********************************************************
This imports data from Callfire from our July 2022 roll out

Created July 2022
Author Laura Gee

Updated November 23 2024 by Owen
*********************************************************/
clear all
cd "$data/2_field_experiment/july data/Callfire Spreadsheets"

//Creating variables that will allow date stamping files
local c_date = c(current_date)
local c_time = c(current_time)
local c_time_date = "`c_date'"+"_" +"`c_time'"
local time_string = subinstr("`c_time_date'", ":", "_", .)
local time_string = subinstr("`time_string'", " ", "_", .)


import delimited "export.csv", varnames(1) stringcols(_all)

save ImportCallfireJuly22`time_string', replace
clear

//should be 159 if 160 sheets
local i=1
foreach a of numlist 1/159 {
import delimited "export (`i').csv", varnames(1) stringcols(_all)
append using ImportCallfireJuly22`time_string' 
save ImportCallfireJuly22`time_string', replace
local i=`i'+1
di `i'
clear
}


use ImportCallfireJuly22`time_string' //Creates date stamped file of the imported Callfire data
gen Wave=5
save, replace

cd "$data/2_field_experiment/july data"
save ImportCallfireJuly22.dta, replace //Creates non-date stamped version of most current data easily called on by other commands/programs
clear


//----------Clean data------------//
clear all
use "$data/2_field_experiment/july data/ImportCallfireJuly22"

duplicates drop //This will correct any duplicate downloads
unique tonumber //CHECK this should be 160 in full roll out

//Remove phone calls from research team
// DH change
*destring fromnumber, generate(num_fromnumber) force 
gen num_fromnumber = fromnumber
drop if num_fromnumber=="B0116871881" //LG office
drop if num_fromnumber=="E5100121771" //OS cell
drop if num_fromnumber=="E7000101331" //Paris's phone
drop if num_fromnumber=="A0056881251" //Katherine's phone

destring tonumber, replace

do "$scripts/CallFireMayJulyOverlap.do"

save "$data/2_field_experiment/july data/ImportCallfireJuly22.dta", replace


//----------One Phone Call 
keep if CallOrder==1 //17730 -- matches 
cd "$data/2_field_experiment/july data" 
save ImportCallfireJuly22_ONEcall.dta, replace
